//
//  StockChartDataService.m
//  Stock
//
//  Created by sun black on 11-7-31.
//  Copyright 2011年 __MyCompanyName__. All rights reserved.
//

#import "StockChartDataService.h"

@implementation StockChartDataService

-(void)queryDataWithChartType:(NSString *)type andStockId:(NSString *)stockId{
    NSString *urlStr = [[NSString alloc] initWithFormat:@"%@jf/stock/%@/%@.jf",kHostName,type,stockId];
    NSLog(@"%@",urlStr);
    NSURL *url = [[NSURL alloc] initWithString:urlStr]; 
    ASIHTTPRequest *request = [[ASIHTTPRequest alloc] initWithURL:url];
    request.delegate = self;
    [request startAsynchronous];
    [self.workingRequests addObject:request];
    [request release];
    [url release];
    [urlStr release];
}
-(void)queryChartDataWithUri:(NSString *)uri{
    NSString *urlStr = [[NSString alloc] initWithFormat:@"%@%@",kHostName,uri];
    NSLog(@"%@",urlStr);
    NSURL *url = [[NSURL alloc] initWithString:urlStr]; 
    ASIHTTPRequest *request = [[ASIHTTPRequest alloc] initWithURL:url];
    request.delegate = self;
    [request startAsynchronous];
    [self.workingRequests addObject:request];
    [request release];
    [url release];
    [urlStr release];
}

#pragma mark -delegate callback
- (void)requestFinished:(ASIHTTPRequest *)request{
    NSString *responseString = [request responseString];
    NSDictionary *result = [responseString JSONValue];
    [self.delegate requestFinishedWithResult:result andUserinfo:request.userInfo];
}

- (void)requestFailed:(ASIHTTPRequest *)request{
    NSLog(@"request error");
    [self.delegate requestFinishedwithError:request.error andUserinfo:request.userInfo];
}

@end
